package com.bjsdzk.collector.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.bjsdzk.backend.rpc.OpenPlatformService;
import com.bjsdzk.collector.core.Result;
import com.bjsdzk.collector.core.ResultGenerator;
import com.bjsdzk.collector.entity.xiyu.XiyuFault;
import com.bjsdzk.collector.platform.coap.utils.JsonUtil;
import com.bjsdzk.collector.rpc.XiYuServiceimp;
import com.bjsdzk.collector.serviceImp.TelecomSecondService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/telecomSencondreceive")
public class TelecomSecondReceiveController {
	
	private static Logger logger = LoggerFactory.getLogger(TelecomSecondReceiveController.class);
	@Autowired
    private MongoTemplate mongoTemplate;
    @Reference( check = false,version ="1.0.0")
    private OpenPlatformService openPlatformService;
    
    @Autowired
    private TelecomSecondService telecomSecondService;
    
    @PostMapping("/deviceAdd")
    public Result recvDeviceAdd( Object message){
    	logger.debug("telecom flatform deviceAdd callback"+message);
        return ResultGenerator.genSuccessResult("ok");
    }

    @PostMapping("/updateDeviceInfo")
    public Result updateDeviceInfo(@RequestBody Object message){
        //{notifyType=deviceInfoChanged, deviceId=01006f25-ab60-4a7e-8b0a-6dcfa15e43cc, gatewayId=0010256458, deviceInfo={swVersion=xxx, name=Sensor_12, description=smock detector, model=90, fwVersion=xxx, protocolType=zigbee, type=90, mac=xxx, manufacturer=wulian, hwVersion=xxx}}
    	logger.debug("telecom flatform updateDeviceInfo callback "+message);
        return ResultGenerator.genSuccessResult(message);
    }
    

    @PostMapping("/updateDeviceData")
	public Result updateDeviceData(@RequestBody Object message) {
    	logger.debug("telecom flatform updateDeviceData callback" + message);
		return ResultGenerator.genSuccessResult(message);
	}

    @PostMapping("/deletedDevice")
    @SuppressWarnings("unchecked")
    public Result deletedDevice(@RequestBody Object message){
    	logger.debug("telecom flatform deletedDevice callback"+message);
        Map<String,String> data = new HashMap<>();
        data = JsonUtil.jsonString2SimpleObj(message.toString(), data.getClass());
        return ResultGenerator.genSuccessResult(data);
    }
    
    @PostMapping("/reportCmdExecResult")
    @SuppressWarnings("unchecked")
    public Result reportCmdExecResult(@RequestBody Object message){
        Map<String,String> data = new HashMap<>();
        data = JsonUtil.jsonString2SimpleObj(message.toString(), data.getClass());
        logger.debug("telecom flatform callback reportCmdExecResult"+message);
        return ResultGenerator.genSuccessResult(data);
    }
    
    @GetMapping("/subscrib")
    public String subscrib(String deviceType){
        return telecomSecondService.subscribe(deviceType);
    }
    
    
}
